package com.itlong.cloud.operate.resource;

import com.itlong.cloud.POJO.DTO.operate.OperateGroupGetPageDTO;
import com.itlong.cloud.POJO.PO.OperateGroupPO;
import com.itlong.cloud.operate.service.IOperateGroupService;
import com.itlong.cloud.user.operate.IOperateGroupServiceClient;
import com.itlong.cloud.utils.page.Page;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <desc>
 *      运营-组织业务处理暴露接口实现类
 * </desc>
 *
 * @createDate 2017/09/14
 */
@RestController
public class OperateGroupServiceResource implements IOperateGroupServiceClient{

    private static final Logger LOG = LoggerFactory.getLogger(OperateGroupServiceResource.class);

    @Autowired
    IOperateGroupService iOperateGroupService;

    /**
     * <desc>
     *      获取分页列表
     * </desc>
     *
     * @return page
     * @author Jiaqi.X
     * @createDate 2017/09/15
     */
    @RequestMapping(path = "/operate/system/group/getPage")
    @Override
    public Page<OperateGroupPO> getPage(@RequestBody OperateGroupGetPageDTO pageDTO) throws Exception {
        return iOperateGroupService.getPage(pageDTO);
    }

    /**
     * <desc>
     *      保存组织
     * </desc>
     *
     * @param operateGroupPO
     * @return
     * @author Jiaqi.X
     * @createDate 2017/09/14
     */
    @Override
    @RequestMapping(path = "/operate/system/group/save")
    public Integer save(@RequestBody OperateGroupPO operateGroupPO) throws Exception {
        return iOperateGroupService.save(operateGroupPO);
    }

    /**
     * <desc>
     *      更新组织
     * </desc>
     *
     * @param operateGroupPO
     * @return
     * @author Jiaqi.X
     * @createDate 2017/09/14
     */
    @Override
    @RequestMapping(path = "/operate/system/group/updateGroup")
    public Integer update(@RequestBody OperateGroupPO operateGroupPO) throws Exception {
        return iOperateGroupService.update(operateGroupPO);
    }

    /**
     * <desc>
     *      根据id查询组织
     * </desc>
     *
     * @param operateGroupPO
     * @return
     * @author Jiaqi.X
     * @createDate 2017/09/27
     */
    @Override
    @RequestMapping(path = "/operate/system/group/getOne")
    public OperateGroupPO getOne(@RequestBody OperateGroupPO operateGroupPO){
        return iOperateGroupService.getOne(operateGroupPO);
    }

    /**
     * <desc>
     *      禁用或启用组织
     * </desc>
     *
     * @param operateGroupPO 组织实体
     * @return
     * @author Jiaqi.X
     * @createDate 2017/09/27
     */
    @Override
    @RequestMapping(path = "/operate/system/group/banOrUse")
    public Integer banOrUse(@RequestBody OperateGroupPO operateGroupPO) throws Exception {
        return iOperateGroupService.update(operateGroupPO);
    }

    /**
     * <desc>
     *      获取所有组织
     * </desc>
     *
     * @return
     * @author Jiaqi.X
     * @createDate 2017/09/29
     */
    @Override
    @RequestMapping(path = "/operate/system/group/getList")
    public List<OperateGroupPO> getList() {
        return iOperateGroupService.getList();
    }

    /**
     * <desc>
     *       部门分配人员
     * </desc>
     *
     * @param groupId    部门id
     * @param allotUsers    需要分配的人员id 多个，号分隔
     * @param userIds 当前列表所有人员id 多个，号分隔
     * @return sql执行行数
     * @author Jiaqi.X
     * @createDate 2017/10/10
     */
    @RequestMapping(path = "/operate/system/group/saveGroupUsers")
    @Override
    public Integer saveGroupUsers(
                @RequestParam("groupId") String groupId,
                @RequestParam("allotUsers") String allotUsers,
                @RequestParam("userIds") String userIds) throws Exception{
        return iOperateGroupService.saveGroupUsers(groupId,allotUsers,userIds);
    }


}
